package demo07;

import java.util.ArrayList;
import java.util.Collections;
import java.util.TreeSet;

public class PokerDemo04 {
    public static void main(String[] args) {

        //创建ArrayList，存储编号
        ArrayList<Poker> array = new ArrayList<>();

        //创建花色数组和点数数组
        String[] colors = {"♦", "♣", "♥", "♠"};
        String[] numbers = {"3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A", "2"};

        //从0开始往HashMap里面存储编号，并存储对应的牌。同时往ArrayList里面存储编号
        int index = 0;

        for (String number : numbers) {
            for (String color : colors) {
                array.add(new Poker(index, color + number));
                index++;
            }
        }
        array.add(new Poker(index, "小王"));
        index++;
        array.add(new Poker(index, "大王"));

        //洗牌(洗的是编号)，用Collections的shuffle()方法实现
        Collections.shuffle(array);

        //发牌(发的也是编号，为了保证编号是排序的，创建
        // TreeSet集合接收)
        TreeSet<Poker> lqxSet = new TreeSet<>();
        TreeSet<Poker> lySet = new TreeSet<>();
        TreeSet<Poker> fqySet = new TreeSet<>();
        TreeSet<Poker> dpSet = new TreeSet<>();

        for (int i = 0; i < array.size(); i++) {
            Poker x = array.get(i);
            if (i >= array.size() - 3) {
                dpSet.add(x);
            } else if (i % 3 == 0) {
                lqxSet.add(x);
            } else if (i % 3 == 1) {
                lySet.add(x);
            } else if (i % 3 == 2) {
                fqySet.add(x);
            }
        }

        //看牌，也就是三个玩家分别遍历自己的牌
        lookPoker("林青霞", lqxSet);
        lookPoker("柳岩", lySet);
        lookPoker("风清扬", fqySet);
        lookPoker("底牌", dpSet);
    }

    //看牌的方法
    public static void lookPoker(String name, TreeSet<Poker> array) {
        System.out.print(name + "的牌是：");
        for (Poker poker : array) {
            System.out.print(poker.getName() + " ");
        }
        System.out.println();
    }
}